<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录页面</title>

    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/img/favicon.ico}"/>
    <link rel="stylesheet" type="text/css"
          th:href="@{/plugins/bootstrap/css/bootstrap.min.css}">
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/plugins/bootstrap/js/bootstrap.bundle.js}"></script>

    <link rel="stylesheet" type="text/css"
          th:href="@{/plugins/font-awesome/css/font-awesome.min.css}">
    <script>
        // 假设当前是iframe，向父容器发送消息
        window.parent.postMessage("IN_LOGIN_PAGE_EVENT", '*');

    </script>

    <!-- 自定义样式 -->
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f8f9fa;
        }

        .form-login {
            background-color: #fff;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 0 10px #ccc;
            max-width: 500px;
            width: 100%;
        }

        .form-login h3 {
            font-size: 24px;
            color: #333;
            margin-bottom: 20px;
            text-align: center;
        }

        .form-login .form-control {
            border-radius: 0px;
            padding-left: 40px;
            font-size: 16px;
        }

        .form-login .btn-primary {
            background-color: #007bff;
            border-color: #007bff;
            border-radius: 0px;
            font-size: 16px;
            width: 100%;
            margin-top: 20px;
            padding: 0px;
            line-height: 38px;
        }

        .form-login .form-check {
            margin-top: 10px;
            margin-bottom: 20px;
        }

        .form-login .form-check-label {
            font-size: 16px;
        }

        body {
            background: url(/img/svg/bg.svg) no-repeat center center fixed;
            background-size: cover;
        }

        .form-group-item {
            position: relative;
        }

        .form-group-item i {
            width: 20px;
            height: 20px;
            position: absolute;
            line-height: 37px;
            left: 15px;
        }
        .form-group > label {
            display: inline-block;
            margin-top: 0.3rem;
            margin-bottom: 0.5rem;
        }
        .my-form-check {
            margin-right: 8px;
            padding-top: 15px;
            display: flex;
            align-items: center;
            user-select: none;
        }
        .my-form-check > label {
            cursor: pointer;
        }
    </style>
</head>
<body id="login_body" style="display: none">

<div class="form-login">
    <h3>信息收集系统</h3>
    <form id="login-form">
        <div class="form-group">
            <label for="username">用户名：</label>
            <div class="form-group-item">
                <i class="fa fa-user"></i>
                <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名">
            </div>
        </div>
        <div class="form-group">
            <label for="password">密码：</label>
            <div class="form-group-item">
                <i class="fa fa-lock" aria-hidden="true"/></i>
                <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码">
            </div>
        </div>
        <div class="my-form-check">
            <input type="checkbox" class="my-form-check" id="rememberMe">
            <label class="form-check-label" for="rememberMe">记住我</label>
        </div>
<!--        <div class="form-check">-->
<!--            <input class="form-check-input" type="radio" name="type" id="user" value="0" checked>-->
<!--            <label class="form-check-label" for="user">-->
<!--                <i class="fa fa-users" aria-hidden="true" /></i>-->
<!--                我是学生-->
<!--            </label>-->
<!--        </div>-->
<!--        <div class="form-check">-->
<!--            <input class="form-check-input" type="radio" name="type" id="admin" value="1">-->
<!--            <label class="form-check-label" for="admin">-->
<!--                <i class="fa fa-user" aria-hidden="true" /></i>-->
<!--                我是老师-->
<!--            </label>-->
<!--        </div>-->
        <a href="/register.html" style="float: right;">还没有注册？</a>
        <button type="submit" class="btn btn-primary">登录</button>
    </form>
</div>
<script type="module">
    import {POST} from "/js/request.js";
    // 监听 Form 表单提交事件
    $("#login-form").on('submit', function (event) {
        let loginForm = {
            username: $("#username").val(),
            password: $("#password").val(),
            rememberMe: $("#rememberMe").prop('checked')
        }
        POST("/login", loginForm).then(result => {
            if (result.success) {
                window.location.href = "/manage.html";
            } else {
                alert("登录失败！" + result.message);
            }
        })

        // 阻止默认的表单提交行为
        event.preventDefault();
    });
    // 页面显示
    document.getElementById("login_body").style.display="flex";

</script>
</body>
</html>
